<!-- from 7 5 2 7 1 8 9 2 0 -->
<!-- 用的InDetail修改 -->
<template>
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :style="cardStyle" :bordered="false">
        <!-- 查询区域
        projectId 调出仓库
        projectIdto 调入仓库
        -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item :label="$t('manuManagement.documentNo')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input :placeholder="$t('manuManagement.pleaseEnterTheDocumentNumber')" v-model="queryParam.number"></a-input>
                </a-form-item>
              </a-col>
              
              <a-col :md="6" :sm="24">
                <a-form-item :label="$t('reportQuery.customer')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-select :placeholder="$t('reportQuery.selectCustomer')" v-model="queryParam.organId"
                    :dropdownMatchSelectWidth="false" showSearch allow-clear optionFilterProp="children">
                    <a-select-option v-for="(item,index) in supList" :key="index" :value="item.id">
                      {{ item.supplier }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="单据日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-range-picker
                    style="width: 100%"
                    v-model="queryParam.createTimeRange"
                    :default-value="defaultTimeStr"
                    format="YYYY-MM-DD"
                    :placeholder="['开始时间', '结束时间']"
                    @change="onDateChange"
                  />
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24" >
                <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons table-operator">
                  <a-button type="primary" @click="searchQuery">{{$t('manuManagement.query')}}</a-button>
                  <ColumnsSetting style="ma" @columnsChange="columnsChange" :columns="columns"></ColumnsSetting>
                  <a-button v-if="btnEnableList.indexOf(5) > -1" style="margin-left: 8px" v-print="'#reportPrint'" icon="printer">{{$t('reportQuery.print')}}</a-button>
                  <a-button v-if="btnEnableList.indexOf(5) > -1"  style="margin-left: 8px" @click="generatePrintData" icon="printer">{{$t('inPrint.other') + $t('reportQuery.print')}}</a-button>
                  <a-button v-if="btnEnableList.indexOf(3) > -1" :loading="downLoading" style="margin-left: 8px" @click="exportExcel" icon="download">{{$t('reportQuery.export')}}</a-button>
                  <a @click="handleToggleSearch" style="margin-left: 8px">
                    {{ toggleSearchStatus ? $t('manuManagement.putAway'):$t('manuManagement.open') }}
                    <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
                  </a>
                </span>
              </a-col>
              <!-- <template v-if="toggleSearchStatus">
                <a-col :md="6" :sm="24">
                  <a-form-item label="仓库" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-select
                      optionFilterProp="children"
                      :dropdownMatchSelectWidth="false"
                      showSearch allow-clear style="width: 100%"
                      placeholder="请选择仓库"
                      v-model="queryParam.depotId">
                      <a-select-option v-for="(depot,index) in depotList" :value="depot.id">
                        {{ depot.depotName }}
                      </a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :md="6" :sm="24">
                  <a-form-item label="对方仓库" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-select
                      optionFilterProp="children"
                      :dropdownMatchSelectWidth="false"
                      showSearch allow-clear style="width: 100%"
                      placeholder="请选择仓库"
                      v-model="queryParam.anotherDepotId">
                      <a-select-option v-for="(depot,index) in depotList" :value="depot.id">
                        {{ depot.depotName }}
                      </a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :md="6" :sm="24">
                  <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input placeholder="请输入备注" v-model="queryParam.remark"></a-input>
                  </a-form-item>
                </a-col>
              </template> -->
            </a-row>
          </a-form>
        </div>
        
        <!-- table区域-begin -->
        <section ref="print" id="reportPrint">
          <a-table
            bordered
            ref="table"
            size="middle"
            :rowKey="record=>record.id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="false"
            :scroll="scroll"
            :loading="loading"
            @change="handleTableChange">
            <span slot="defaultNumber" slot-scope="text, record">
              <a @click="myHandleDetail(record)">{{record.defaultNumber}}</a>
            </span>
            <template slot="customRenderStatus" slot-scope="status">
              <a-tag v-if="status == '0'" color="red">{{$t('otherJS.hangInTheAir')}}</a-tag>
              <a-tag v-if="status == '1'" color="green">{{$t('otherJS.completed')}}</a-tag>
            </template>
            
            <template slot="CustomerOrderNumber" slot-scope="text, record">
              <a @click="myHandleDetail(record, $t('reportQuery.orderCount'))">{{text}}</a>
            </template>
            <template slot="straightNumber" slot-scope="text, record">
              <a @click="showPurchaseTrackingInOutList(record, $t('reportQuery.orderCount'))">{{text}}</a>
            </template>
            <template slot="quotationNumber" slot-scope="text, record">
              <a @click="showPurchaseTrackingInOutList(record, $t('reportQuery.quotationNumber'))">{{text}}</a>
            </template>
            <template slot="purchaseNumber" slot-scope="text, record">
              <a @click="showPurchaseTrackingInOutList(record, $t('reportQuery.purchaseOrderNumber'))">{{text}}</a>
            </template>
            
            <template slot="exchangeNumber" slot-scope="text, record">
              <a @click="showPurchaseTrackingInOutList(record, $t('reportQuery.exchangeNumber'))">{{text}}</a>
            </template>
            <template slot="breakNumber" slot-scope="text, record">
              <a @click="showPurchaseTrackingInOutList(record, $t('reportQuery.breakNumber'))">{{text}}</a>
            </template>
            <template slot="affirmNumber" slot-scope="text, record">
              <a @click="showPurchaseTrackingInOutList(record, $t('reportQuery.finishNumber'))">{{text}}</a>
            </template>
            <template slot="aogNumber" slot-scope="text, record">
              <a @click="showPurchaseTrackingInOutList(record, $t('reportQuery.PurchaseAcceptanceNumber'))">{{text}}</a>
            </template>
          </a-table>
          <a-row :gutter="24" style="margin-top: 8px;text-align:right;">
            <a-col :md="24" :sm="24">
              <a-pagination @change="paginationChange" @showSizeChange="paginationShowSizeChange"
                size="small"
                show-size-changer
                :showQuickJumper="true"
                :current="ipagination.current"
                :page-size="ipagination.pageSize"
                :page-size-options="ipagination.pageSizeOptions"
                :total="ipagination.total"
                :show-total="(total, range) => $t('setailManagement.common')+` ${total-Math.ceil(total/ipagination.pageSize)} `+$t('setailManagement.strip')">
                <template slot="buildOptionText" slot-scope="props">
                  <span>{{ props.value-1 }}{{$t('setailManagement.strip')}}/{{$t('setailManagement.page')}}</span>
                </template>
              </a-pagination>
            </a-col>
          </a-row>
        </section>
        <!-- table区域-end -->
        <!-- 表单区域 -->
        <bill-detail ref="modalDetail"></bill-detail>
        <DirectOrderTrackingInModual ref="purchaseTrackingInOutList"></DirectOrderTrackingInModual>
      </a-card>
    </a-col>
  </a-row>
</template>
<script>
  import BillDetail from '../bill/dialog/BillDetail'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getNowFormatYear, openDownloadDialog, sheet2blob} from "@/utils/util"
  import {getAction} from '@/api/manage'
  import {findBySelectCus, findBillDetailByNumber} from '@/api/api'
  import DirectOrderTrackingInModual from '@/views/report/modules/directOrderTrackingInModual'
  import JEllipsis from '@/components/jeecg/JEllipsis'
  import moment from 'moment'
  export default {
    name: "DirectSchedule",
    mixins:[JeecgListMixin],
    components: {
      BillDetail,
      JEllipsis,
      DirectOrderTrackingInModual
    },
    data () {
      return {
        labelCol: {
          span: 5
        },
        wrapperCol: {
          span: 18,
          offset: 1
        },
        // 查询条件
        queryParam: {
          organId: '',
          status: '',
          defaultNumber: '',
          materialParam:'',
          anotherDepotId: '',
          depotId: '',
          beginTime: getNowFormatYear() + '-01-01',
          endTime: moment().format('YYYY-MM-DD'),
          subType: "厂家直发进度表",
          remark: ''
        },
        ipagination:{
          pageSize: 11,
          pageSizeOptions: ['11', '21', '31', '101', '201']
        },
        dateFormat: 'YYYY-MM-DD',
        currentDay: moment().format('YYYY-MM-DD'),
        downLoading:false,//导出按钮loading
        defaultTimeStr: '',
        supList: [],
        depotList: [],
        tabKey: "1",
        // 表头
        columns: [{
            title: this.$t('defaultTranslate.lineNumber'),dataIndex: 'rowIndex',width:'3%', align: 'center',
            customRender: (t,r,index) => parseInt(index)+1
          },
          {title:this.$t('reportQuery.documentDate'), dataIndex: 'operTimeStr',align: 'center', width: 30},
          {title:this.$t('manuManagement.customer'), dataIndex: 'supplier',align: 'left', width: 50},
          {title:this.$t('systemManagement.manufacturersOrder'),dataIndex: 'defaultNumber',align: 'center',width: 40, scopedSlots: { customRender: 'defaultNumber'}},
          // 订单状态
          {title:this.$t('reportQuery.orderStatus'), dataIndex: 'status',align: 'center', width: 20,
            customRender: (text,record) => {
              switch (record.status) {
                case '0':
                  return (<a-tag color="red">{this.$t('manuManagement.notApproved')}</a-tag>)
                case '1': 
                  return (<a-tag color="green">{this.$t('manuManagement.reviewed')}</a-tag>)
                case '2': 
                  return (<a-tag color="blue">{this.$t('manuManagement.completeSales')}</a-tag>)
                case '3':
                  return (<a-tag color="cyan">{this.$t('manuManagement.partialSales')}</a-tag>)
              }
            }
          },
          // 采购状态
          {title:this.$t('reportQuery.purchaseStatus'), dataIndex: 'purchaseStatus',align: 'center', width: 20,
            customRender: (text,record) => {
              switch (record.purchaseStatus) {
                case '0':
                  return (<a-tag color="red">{ this.$t('manuManagement.notPurchased') }</a-tag>)
                case '2': 
                  return (<a-tag color="cyan">{ this.$t('manuManagement.completePurchase') }</a-tag>)
                case '3': 
                  return (<a-tag color="blue">{ this.$t('manuManagement.partialProcurement') }</a-tag>)
              }
              
            }
          },
          {title: this.$t('otherJS.directCustomer'), dataIndex: 'supplier', width: 80},
          {title: this.$t('otherJS.numberOfDirectHair'), dataIndex: 'straightNumber', width: 80},
          {title: this.$t('otherJS.purchaseQuantity'), dataIndex: 'purchaseNumber', width: 80},
          {title: this.$t('otherJS.arrivalAcceptanceQuantity'), dataIndex: 'aogNumber', width: 80},
          {title: this.$t('otherJS.purchaseWarehousing'), dataIndex: 'affirmNumber', width: 80},
          {title: this.$t('otherJS.straightHairHandler'), dataIndex: 'straightName', width: 80},
          {title: this.$t('manuManagement.documentDate'), dataIndex: 'createTimeStr', width: 80},
          // {title: '条码', dataIndex: 'barCode', width: 80},
          // {title: '名称', dataIndex: 'mname', width: 120, ellipsis:true},
          // {title: '规格', dataIndex: 'standard', width: 60, ellipsis:true},
          // {title: '型号', dataIndex: 'model', width: 60, ellipsis:true},
          // {title: '单位', dataIndex: 'mUnit', width: 60, ellipsis:true},
          // {title: '数量', dataIndex: 'operNumber', sorter: (a, b) => a.operNumber - b.operNumber, width: 60},
          // {title: '单价', dataIndex: 'unitPrice', sorter: (a, b) => a.unitPrice - b.unitPrice, width: 60},
          // {title: '金额', dataIndex: 'allPrice', sorter: (a, b) => a.allPrice - b.allPrice, width: 60},
          { title: this.$t('manuManagement.state'), dataIndex: 'lastStatus', width: 80,
            scopedSlots: { customRender: 'customRenderStatus' }
          },
          // 验收状态
          {title:this.$t('reportQuery.acceptanceStatus'), dataIndex: 'receiveStatus',align: 'center', width: 20,
            customRender: (text,record) => {
              switch (record.receiveStatus) {
                case '0':
                  return (<a-tag color="red">{this.$t('manuManagement.unReceived')}</a-tag>)
                case '1': 
                  return (<a-tag color="green">{this.$t('manuManagement.received')}</a-tag>)
                case '2': 
                  return (<a-tag color="cyan">{this.$t('manuManagement.partReceived')}</a-tag>)
              }
            }
          },
          // 换货状态
          {title:this.$t('reportQuery.exchangeStatus'), dataIndex: 'exchangeStatus',align: 'center', width: 20,
            customRender: (text,record) => {
              // 0无 1已完成 2未完成
              switch (record.exchangeStatus) {
                case '2':
                  return (<a-tag color="red">{this.$t('reportQuery.exchangeNotCompleted')}</a-tag>)
                case '1': 
                  return (<a-tag color="green">{this.$t('reportQuery.exchanged')}</a-tag>)
              }
            }
          },
          // 订单数量
          {title:this.$t('reportQuery.orderCount'), dataIndex: 'straightNumber',align: 'center', width: 15,scopedSlots: { customRender: 'straightNumber'}},

          // 采购下达数
          {title:this.$t('reportQuery.purchaseOrderNumber'), dataIndex: 'purchaseNumber',align: 'center', width: 15,scopedSlots: { customRender: 'purchaseNumber'}},
          // 报价数
          {title:this.$t('reportQuery.quotationNumber'), dataIndex: 'quotationNumber',align: 'center', width: 15,scopedSlots: { customRender: 'quotationNumber'}},
          // 换货数
          {title:this.$t('reportQuery.exchangeNumber'), dataIndex: 'exchangeNumber',align: 'center', width: 15,scopedSlots: { customRender: 'exchangeNumber'}},
          // 报损数
          {title:this.$t('reportQuery.breakNumber'), dataIndex: 'breakNumber',align: 'center', width: 15,scopedSlots: { customRender: 'breakNumber'}},
          // 入库数
          {title:this.$t('reportQuery.finishNumber'), dataIndex: 'affirmNumber',align: 'center', width: 15,scopedSlots: { customRender: 'affirmNumber'}},
          // 采购验收数
          {title:this.$t('reportQuery.PurchaseAcceptanceNumber'), dataIndex: 'aogNumber',align: 'center', width: 15,scopedSlots: { customRender: 'aogNumber'}}
        ],
        url: {
          list: "/depotHead/factoryOutLet",
        }
      }
    },
    created () {
      this.getDepotData()
      this.initSupplier()
      this.defaultTimeStr = [moment(getNowFormatYear() + '-01-01', this.dateFormat), moment(this.currentDay, this.dateFormat)]
    },
    methods: {
      moment,
      getQueryParams() {
        let param = Object.assign({}, this.queryParam, this.isorter);
        param.field = this.getQueryField();
        param.pageNum = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize-1;
        return param;
      },
      onDateChange: function (value, dateString) {
        // console.log(dateString[0],dateString[1]);
        this.queryParam.beginTime=dateString[0];
        this.queryParam.endTime=dateString[1];
      },
      initSupplier() {
        let that = this;
        findBySelectCus({}).then((res)=>{
          if(res) {
            that.supList = res;
          }
        });
      },
    // 查看详情
    showPurchaseTrackingInOutList(record, title) {
      this.$set(record,'number',record.defaultNumber)
      this.$refs.purchaseTrackingInOutList.show(record, title);
      this.$refs.purchaseTrackingInOutList.disableSubmit = false;
    },
      getDepotData() {
        getAction('/depot/findDepotByCurrentUser').then((res)=>{
          if(res.code === 200){
            this.depotList = res.data;
          }else{
            this.$message.info(res.data);
          }
        })
      },
      myHandleDetail(record) {
        record.newType = '厂家直发订单'
        findBillDetailByNumber({ number: record.defaultNumber }).then((res) => {
          if (res && res.code === 200) {
            this.handleDetail(res.data, record.newType);
          }
        })
      },
      searchQuery() {
        if(this.queryParam.beginTime == '' || this.queryParam.endTime == ''){
          this.$message.warning(this.$t('reportQuery.pleaseDate'))
        } else {
          this.loadData(1);
        }
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>